/**
 * Created by admin on 2017/4/11.
 */
define(['app', 'filters/filters'], function(app) {
    app.register.controller('proIndex', function ($scope, $http, $state, $sce, $stateParams, $rootScope,$cookieStore,$interval) {
        // $rootScope.hasHeader = 0;//有顶部的header
        $scope.top = 0;
        $scope.tiao_zhuan = function(){
            $("html,body").animate({scrollTop:4200},1000)
        }
        $(window).scroll(function(event){
            if($(window).scrollTop()>0){
                $(".header_wrap_product1").addClass("header_wrap_style");
            }else{
                $(".header_wrap_product1").removeClass("header_wrap_style");
            }
        });
        //点击下方报名
        $scope.goPro_if = function(page){
            if($cookieStore.get('userInfo')){
                var url = $state.href('app.signUp');
                window.open(url,'_blank');

            }else{
                $cookieStore.put("tiaozhuan_sign",1);
                var url = $state.href('access.login');
                window.open(url,'_blank');
            }
        }
        //僵尸
        // $scope.prev = function(){
        //
        // }
        // $scope.next = function(){
        //     // $(".ul_box ul").animate({
        //     //     left:'-292px'
        //     // },function(){
        //     //     $(".ul_box ul").append($(".ul_box ul li").eq(0));
        //     // });
        //     $(".ul_box ul li").eq(0).fadeOut();
        //     $(".ul_box ul").append($(".ul_box ul li").eq(0));
        // }
        //讲师
        var timer=null;
        $scope.lunBo={
            step:0,
            left:0,
            speed:40,
            go:function(){
                timer=null;
                $interval.cancel(timer)
                if ($scope.lunBo.left>-326*$scope.lunBo.step){
                    $scope.lunBo.speed=-40
                }else{
                    $scope.lunBo.speed=40
                }
                timer= $interval(function(){
                    $scope.lunBo.left=$scope.lunBo.left+$scope.lunBo.speed
                    angular.element(document.getElementById('jiangshi')).css('left',$scope.lunBo.left+'px')
                    if ($scope.lunBo.speed<0&&$scope.lunBo.left<-326*$scope.lunBo.step){
                        angular.element(document.getElementById('jiangshi')).css('left',-326*$scope.lunBo.step+'px')
                        $scope.lunBo.left=-326*$scope.lunBo.step
                        $interval.cancel(timer)
                        angular.element(document.getElementById('current')).find('li').css('display','none')
                        //console.log($scope.lunBo.step)
                        angular.element(document.getElementById('current')).find('li').eq($scope.lunBo.step>=3?$scope.lunBo.step-3:$scope.lunBo.step+1).css('display','block')
                    }else if ($scope.lunBo.speed>0&&$scope.lunBo.left>-326*$scope.lunBo.step){
                        angular.element(document.getElementById('jiangshi')).css('left',-326*$scope.lunBo.step+'px')
                        $scope.lunBo.left=-326*$scope.lunBo.step
                        $interval.cancel(timer)
                        angular.element(document.getElementById('current')).find('li').css('display','none')
                        angular.element(document.getElementById('current')).find('li').eq($scope.lunBo.step>=3?$scope.lunBo.step-3:$scope.lunBo.step+1).css('display','block')
                    }
                },20)
                //angular.element(document.getElementById('bbb')).css('left',-326*scope.step+'px')
            },
            prev:function(){
                if($scope.lunBo.step==4){
                    $scope.lunBo.step=0;
                    $scope.lunBo.left=-326*($scope.lunBo.step)
                }
                $scope.lunBo.step++
                $scope.lunBo.go();
            },
            next:function(){
                if($scope.lunBo.step==0){
                    $scope.lunBo.step=4;
                    $scope.lunBo.left=-326*($scope.lunBo.step)

                }
                $scope.lunBo.step--
                /*   if($scope.lunBo.step<=-1){
                 $scope.lunBo.step=2;
                 $scope.lunBo.left=-326*($scope.lunBo.step-1)

                 }*/
                $scope.lunBo.go();
            },
            current:function(i){
                if(i==0){
                    if($scope.lunBo.step==0||$scope.lunBo.step==4){
                        $scope.lunBo.next()
                    }else{
                        $scope.lunBo.prev()
                    }
                }else if(i==1){
                    if($scope.lunBo.step==1){
                        $scope.lunBo.next()
                    }else{
                        $scope.lunBo.prev()
                    }
                }else if(i==2){
                    if($scope.lunBo.step==2){
                        $scope.lunBo.next()
                    }else{
                        $scope.lunBo.prev()
                    }
                }else{
                    if($scope.lunBo.step==3){
                        $scope.lunBo.next()
                    }else{
                        $scope.lunBo.prev()
                    }
                }
                /*  if ($scope.lunBo.step==0&&i==0||$scope.lunBo.step==2){
                 $scope.lunBo.prev()
                 }else{
                 $scope.lunBo.next()
                 }*/
            }

        }
    })
})